package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.CheckInDinner;
import com.eling.elcms.travel.model.Dinner;
import com.eling.elcms.travel.service.IDinnerManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Controller
public class DinnerController extends BaseFormController {

	@Autowired
	private IDinnerManager dinnerManager;

	@RequestMapping("/api/dinner/save")
	@ResponseBody
	public Dinner save(@ModelAttribute @ModelFilling Dinner dinner) {
		return dinnerManager.save(dinner);
	}

	@RequestMapping("/api/dinner/{pkDinner}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkCarFile) {
		dinnerManager.remove(pkCarFile);
		return new Msg("删除成功");
	}

	@RequestMapping("/api/dinner/query")
	@ResponseBody
	public List<Dinner> query(@ModelAttribute Dinner cond) {
		return dinnerManager.query(cond);
	}

	@RequestMapping("/api/dinner/search*")
	@ResponseBody
	public List<Dinner> search(@ModelAttribute SearchCondition sc, @ModelAttribute Dinner cond) {
		sc.setQueryCondition(cond);
		return dinnerManager.search(sc);
	}

	/**
	 * 入住准备落实单，餐饮落实批量设置（用于批量新增和单条数据新增，单条编辑时不走此接口）
	 * 
	 * @param dinner
	 * @param pkCheckInImplement
	 * @param pkCheckInDinner
	 * @param startDate
	 * @param endDate
	 * @return
	 * @author zhoulin
	 */
	@RequestMapping("/api/dinner/savebatchdinner")
	@ResponseBody
	public CheckInDinner saveBatchDinner(@ModelAttribute Dinner dinner,
			@RequestParam(name = "pkCheckInImplement", required = false) Long pkCheckInImplement,
			@RequestParam(name = "pkCheckInDinner", required = false) Long pkCheckInDinner,
			@RequestParam(name = "startDate", required = false) Date startDate,
			@RequestParam(name = "endDate", required = false) Date endDate) {
		return dinnerManager.saveBatchDinner(dinner, pkCheckInImplement, pkCheckInDinner, startDate, endDate);
	}

	@RequestMapping("/api/dinner/penddinner")
	@ResponseBody
	public CheckInDinner pendDinner(@RequestParam(name = "pkCheckInDinner", required = false) Long pkCheckInDinner,
			@RequestParam(name = "pkDinner", required = false) Long pkDinner) {
		return dinnerManager.pendDinner(pkCheckInDinner, pkDinner);
	}

}
